﻿namespace Amazon.Checkout.ViewModels
{
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using Helpers;
    using Orchard.Localization;

    public class ShippingNewUpdateViewModel : IValidatableObject
    {
        public ShippingNewUpdateViewModel()
        {
            this.T = NullLocalizer.Instance;
        }

        public int ShippingId { get; set; }

        public string IncludedRegionsString { get; set; }

        public IEnumerable<AmazonCheckout.Region> IncludedRegions { get; set; }

        public string ExcludedRegionsString { get; set; }

        public IEnumerable<AmazonCheckout.Region> ExcludedRegions { get; set; }

        public string ShipmentRateType { get; set; }

        public decimal ShipmentBasedShippingRate { get; set; }

        public decimal WeightBasedShippingRate { get; set; }

        public virtual decimal ItemQuantityBasedShippingRate { get; set; }

        public bool PoBoxSupported { get; set; }

        [Required]
        public string DisplayableShippingLabel { get; set; }

        public int ServiceLevel { get; set; }

        public Localizer T { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            switch (this.ShipmentRateType)
            {
                case "shipment":
                    if (this.ShipmentBasedShippingRate <= 0)
                    {
                        yield return new ValidationResult(this.T("The rate specified must be greater than zero.").Text);
                    }

                    break;
                case "weight":
                    if (this.WeightBasedShippingRate <= 0)
                    {
                        yield return new ValidationResult(this.T("The rate specified must be greater than zero.").Text);
                    }

                    break;
                case "item":
                    if (this.ItemQuantityBasedShippingRate <= 0)
                    {
                        yield return new ValidationResult(this.T("The rate specified must be greater than zero.").Text);
                    }

                    break;
            }

            yield break;
        }
    }
}